Telegram Group & Telegram Channel
Иногда нужно создать функцию на основе более универсальной.

Например, у функции int() есть параметр base, который мы хотим зафиксировать, чтобы получить новую функцию base2:


>>> int("10")
10
>>> int("10", 2)
2
>>> def base2(x):
... return int(x, 2)
...
>>> base2("10")
2


functools.partial позволяет сделать то же самое, но точнее и семантически понятнее:


base2 = partial(int, base=2)


Это полезно, когда нужно передать функцию как аргумент другой, более общей функции, но при этом некоторые аргументы должны быть зафиксированы:


>>> map(partial(int, base=2), ["1", "10", "100"])
[1, 2, 4]


Без partial пришлось бы делать так:


>>> map(lambda x: int(x, base=2), ["1", "10", "100"])
[1, 2, 4]


👉@BookPython



tg-me.com/BookPython/3707
Create:
Last Update:

Иногда нужно создать функцию на основе более универсальной.

Например, у функции int() есть параметр base, который мы хотим зафиксировать, чтобы получить новую функцию base2:


>>> int("10")
10
>>> int("10", 2)
2
>>> def base2(x):
... return int(x, 2)
...
>>> base2("10")
2


functools.partial позволяет сделать то же самое, но точнее и семантически понятнее:


base2 = partial(int, base=2)


Это полезно, когда нужно передать функцию как аргумент другой, более общей функции, но при этом некоторые аргументы должны быть зафиксированы:


>>> map(partial(int, base=2), ["1", "10", "100"])
[1, 2, 4]


Без partial пришлось бы делать так:


>>> map(lambda x: int(x, base=2), ["1", "10", "100"])
[1, 2, 4]


👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/BookPython/3707

View MORE
Open in Telegram


Библиотека Python разработчика | Книги по питону Telegram | DID YOU KNOW?

Date: |

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

Библиотека Python разработчика | Книги по питону from us


Telegram Библиотека Python разработчика | Книги по питону
FROM USA